package com.daylightrobbery.server.packet.game.chance;

import com.daylightrobbery.server.packet.game.common.ChanceCardData;
import com.daylightrobbery.server.packet.game.common.ChanceCardReader;
import com.daylightrobbery.server.packet.type.DataPacket;
import com.daylightrobbery.server.packet.type.RoomDataPacket;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.concurrent.ThreadLocalRandom;

@Component
public class CreateChancePacketReq implements RoomDataPacket {
    public static int type = 70001;
    public String uid;
    public int roomId;
    public int pathIndex;
    public String syncId;


    @Override
    public DataPacket process() {
        CreateChancePacketResp resp = new CreateChancePacketResp();
        resp.setUid(uid)
                .setRoomId(roomId)
                .setPathIndex(pathIndex)
                .setSyncId(syncId);
        // 设置卡片相关的属性
        HashMap<Integer, ChanceCardData> data = ChanceCardReader.read();
        int cardType = ThreadLocalRandom.current().nextInt(0, data.size());
        ChanceCardData chanceCardData = data.get(cardType);
        resp.setChanceType(cardType)
                .setMsg(chanceCardData.getMsg())
                .setPlayerGet(chanceCardData.isPlayerGet())
                .setMoney(chanceCardData.getMoney());
        return resp;
    }

    @Override
    public int getType() {
        return type;
    }

    @Override
    public int getRoomId() {
        return roomId;
    }
}
